package cn.school.controller.stu.evaluation;

import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.stu.evaluation.entity.StuEvaTask;
import cn.school.stu.evaluation.service.StuEvaTaskService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author: lx
 * @date: 2023/5/25 10:41
 * @description:
 */
@RestController
@Api(tags = "StuEvaTaskController => 学生考评任务控制器")
@RequestMapping("stu/evaluation/task")
public class StuEvaTaskController {

    @Autowired
    StuEvaTaskService stuEvaTaskService;

    @PostMapping("/createStuEvaTask")
    public CommonResult createStuEvaTask(@RequestBody StuEvaTask task){
        Integer num = stuEvaTaskService.createStuEvaTask(task);
        if(num > 0){
            return CommonResult.success();
        }
        return CommonResult.failed("failed");
    }

    @PostMapping("/findStuEvaTaskPageList")
    public CommonResult<CommonPage<StuEvaTask>> findStuEvaTaskPageList(@RequestBody StuEvaTask vo){
        IPage<StuEvaTask> page = stuEvaTaskService.findStuEvaTaskPageList(vo);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @GetMapping("/findStuEvaScoreTemplateByPlanId/{planId}")
    public CommonResult findStuEvaScoreTemplateByPlanId(@PathVariable("planId") Long planId){
        List<Map<String,Object>> list = stuEvaTaskService.findStuEvaScoreTemplateByPlanId(planId);
        return CommonResult.success(list);
    }

    @GetMapping("/findStuEvaByPlanId/{planId}")
    public CommonResult<List<StuEvaTask>> findStuEvaPlanId(@PathVariable("planId")Long planId){
        List<StuEvaTask> stuEvaByPlanId = stuEvaTaskService.findStuEvaByPlanId(planId);
        return CommonResult.success(stuEvaByPlanId);
    }

    @PostMapping("/delTaskByTaskId/{taskId}")
    public CommonResult delTaskById(@PathVariable("taskId")Long taskId){
        int row = stuEvaTaskService.delTaskByTaskId(taskId);
        if (row > 0) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
}
